<?php
/*
 * author: fabricio s costa
 * version: 1.0
 * site: http://fabriciojf.com
 */
require_once('com/fabriciojf/action/Action.class.php');
require_once('com/fabriciojf/security/Permission.class.php');
require_once('com/fabriciojf/persistence/DaoGenerico.class.php');
require_once('com/fabriciojf/persistence/HistoricoDAO.class.php');

class TicketAbrirAction implements Action {
    public function execute() {
        Permission::requireInRole(array('admin','usuario'));

        $historicoDao = new HistoricoDAO();

        $idTicket = $_POST['idTicket'] . $_GET['idTicket'];

        $ticket = Dao::findForId($idTicket, 'Ticket');
        if (($ticket->getUsuario()->getId() == $_SESSION['idUsuarioLogado']) or (Permission::isInRole(array('admin'))))  {

            $_REQUEST['ticket'] = Dao::findForId($idTicket, 'Ticket');
            $_REQUEST['historico'] = $historicoDao->findForTicket($idTicket);
            require_once('com/fabriciojf/view/TicketAbrir.php');
        } else {
            FrontController::sendRedirect('TicketListar');
        }
    }
}
?>
